package controller.link.game;

import view.client.Console;
import model.Hearer;
import java.io.Serializable;
import controller.Link;
import controller.link.RefreshGameData;
import model.game.Player;
import model.Attendant;
import model.Server;

public class SellItem implements Link, Serializable {
    private String nameItem;

    public SellItem() {
    }

    public SellItem(Hearer h, String nameItem) {
        this.nameItem = nameItem;
        h.send((Link) this);
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        Player player = at.getUser().getPlayer();
        for (int i=0; i < player.getItems().size(); i++){
            if (player.getItems().get(i).getName().equals(nameItem)){
                int value = player.getItems().get(i).getPrice();
                player.setMoney(player.getMoney()+Math.round(value/3));
                player.removeItem(player.getItems().get(i));
                break;
            }
        }
        RefreshGameData rgd = new RefreshGameData();
        rgd.serverUse(server, at);
    }

    @Override
    public void clientUse(Console console) {
    }
}
